package cn.elead.it.sso.sample.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gitee.elead.web.api.ApiResponses;
import com.gitee.elead.web.controller.SuperController;

import cn.elead.it.sso.core.constant.GlobalVariable;
import cn.elead.it.sso.core.model.SsoUser;

/**
 * web cookie方式
 * 
 * @author luopeng
 *
 */
@Controller
public class IndexController extends SuperController {

	@RequestMapping("/")
	public String index(Model model, HttpServletRequest request) {
		SsoUser ssoUser = (SsoUser) request.getAttribute(GlobalVariable.SSO_USER);
		model.addAttribute("ssoUser", ssoUser);
		return "index";
	}

	@ResponseBody
	@RequestMapping("/json")
	public ApiResponses<SsoUser> json(Model model, HttpServletRequest request) {
		SsoUser ssoUser = (SsoUser) request.getAttribute(GlobalVariable.SSO_USER);
		return success(ssoUser);
	}

}